package com.knowledgegraph.web.controller.zhongyao;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.knowledgegraph.common.annotation.Log;
import com.knowledgegraph.common.core.controller.BaseController;
import com.knowledgegraph.common.core.domain.AjaxResult;
import com.knowledgegraph.common.enums.BusinessType;
import com.knowledgegraph.zhongyao.domain.MedicineType;
import com.knowledgegraph.zhongyao.service.IMedicineTypeService;
import com.knowledgegraph.common.utils.poi.ExcelUtil;
import com.knowledgegraph.common.core.page.TableDataInfo;

/**
 * 药材类型Controller
 * 
 * @author ruoyi
 * @date 2023-07-25
 */
@RestController
@RequestMapping("/zhongyao/type")
public class MedicineTypeController extends BaseController
{
    @Autowired
    private IMedicineTypeService medicineTypeService;

    /**
     * 查询药材类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(MedicineType medicineType)
    {
        startPage();
        List<MedicineType> list = medicineTypeService.selectMedicineTypeList(medicineType);
        return getDataTable(list);
    }

    /**
     * 导出药材类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:export')")
    @Log(title = "药材类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MedicineType medicineType)
    {
        List<MedicineType> list = medicineTypeService.selectMedicineTypeList(medicineType);
        ExcelUtil<MedicineType> util = new ExcelUtil<MedicineType>(MedicineType.class);
        util.exportExcel(response, list, "药材类型数据");
    }

    /**
     * 获取药材类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:type:query')")
    @GetMapping(value = "/{medicineTypeKey}")
    public AjaxResult getInfo(@PathVariable("medicineTypeKey") Long medicineTypeKey)
    {
        return AjaxResult.success(medicineTypeService.selectMedicineTypeByMedicineTypeKey(medicineTypeKey));
    }

    /**
     * 新增药材类型
     */
    @PreAuthorize("@ss.hasPermi('system:type:add')")
    @Log(title = "药材类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MedicineType medicineType)
    {
        return toAjax(medicineTypeService.insertMedicineType(medicineType));
    }

    /**
     * 修改药材类型
     */
    @PreAuthorize("@ss.hasPermi('system:type:edit')")
    @Log(title = "药材类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MedicineType medicineType)
    {
        return toAjax(medicineTypeService.updateMedicineType(medicineType));
    }

    /**
     * 删除药材类型
     */
    @PreAuthorize("@ss.hasPermi('system:type:remove')")
    @Log(title = "药材类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{medicineTypeKeys}")
    public AjaxResult remove(@PathVariable Long[] medicineTypeKeys)
    {
        return toAjax(medicineTypeService.deleteMedicineTypeByMedicineTypeKeys(medicineTypeKeys));
    }
}
